// createRouter：创建router实例对象
// createWebHistory：创建history模式的路由

import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
//创建一个路由器实例，并传入 `routes` 配置
const router = createRouter({
    //使用历史模式
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/',
            name: 'layout',
            component: Layout,
            children:[
                {
                    path:'',//home是默认渲染页，这里的path需要置空，当我们渲染/的时候，我们的home页面也会自动得到渲染
                    component:Home,
                },
                {
                    path:'category/:id',
                    component:Category,
                },
                {
                    path:'category/sub/:id',
                    component:SubCategory,
                },
                {
                    path:'detail/:id',
                    component:Detail,
                }
            ],
        },
        {
            path: '/login',
            name: 'login',
            component: Login
        }
    ],
    //路由滚动行为的定制，切换路由的时候，自动滚动到页面顶部
    scrollBehavior(){
        return {
            left:0,
            top:0
        }
    }

})
//导出一个路由器实例
export default router